package com.c.ctgproject.ui.service

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.c.ctgproject.base.BaseViewModel
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.utils.MyLog
import com.c.ctgproject.utils.awaitSync
import com.c.ctgproject.utils.launch
import com.c.ctgproject.utils.userToken
import okhttp3.RequestBody

class ServiceOrderDetailViewModel :BaseViewModel(){

    private val mCommonResult = MutableLiveData<String>()
    val commonResult: LiveData<String> get() = mCommonResult

    private val mResult = MutableLiveData<String>()
    val result: LiveData<String> get() = mResult
    //获取订单详情
    fun getOrderDetail(suborderId: String,enterMode:String?) {
        launch {
            mResult.value = ApiMethods.retrofit.serviceOrderDetail(userToken, suborderId,enterMode).awaitSync()
        }
    }

    private val mPayTypeResult = MutableLiveData<String>()
    val payTypeResult: LiveData<String> get() = mPayTypeResult


    //收款方式
    fun payType(suborderId:String){
        launch {
            mPayTypeResult.value=ApiMethods.retrofit.serviceDetailPayType(userToken,suborderId).awaitSync()
        }
    }

    private val mTrackingResult = MutableLiveData<String>()
    val trackingResult: LiveData<String> get() = mTrackingResult

    fun serviceTrackingList(){
        launch {
            mTrackingResult.value=  ApiMethods.retrofit.serviceTrackingList(userToken).awaitSync()
        }
    }

    private val mConfirmResult = MutableLiveData<String>()
    val confirmResult: LiveData<String> get() = mConfirmResult
    fun serviceOrderConfirm(body:RequestBody){
        MyLog.d("提交订单了")
        launch {
            mConfirmResult.value=ApiMethods.retrofit.serviceOrderConfirm(userToken,body).awaitSync()
        }
    }


    private val mCancelResult = MutableLiveData<String>()
    val cancelResult: LiveData<String> get() = mCancelResult

    fun serviceOrderCancel(suborderId:String,carId:String,remark:String){
        MyLog.d("提交订单了")
        launch {
            mCancelResult.value=ApiMethods.retrofit.serviceOrderCancel(userToken,suborderId, carId, remark).awaitSync()
        }
    }

    //提交订单待沟通
    fun serviceOrderWaitTalk(suborderId:String,carId:String){
        launch {
            mCommonResult.value=ApiMethods.retrofit.serviceOrderWaitTalk(userToken,suborderId, carId).awaitSync()
        }

    }

}